package Package.TCPCommunicationProtocol.TCPAcceptsData;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPAcceptsData {
    public static final void TCPAcceptsData() throws IOException {
//        ServletSocket(int port) 创建绑定到指定端口的服务器套接字
        ServerSocket ss=new ServerSocket(10086);
//        Socket accept() 监听要连接到此的套接字并接受它
        Socket s=ss.accept();
        InputStream is=s.getInputStream();
        byte[] bys = new byte[1024];
        int len = is.read(bys);
        String data = new String(bys,0,len);
        System.out.println("数据是：" + data);
        s.close();
        ss.close();
    }
}
